<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			#box{
				width: 200px;
				height: 100px;
				background-color: green;
				display: none;
			}
		</style>
	</head>
	<body>
		<button id="btn">按钮</button>
		<div id="box">
			
		</div>
		<script type="text/javascript">
			var oBtn = document.getElementById("btn")
			var oBox = document.getElementById("box")
			oBtn.onclick = function  (ev) {
				oBox.style.display = "block"
				stopEvent(ev)
			}
			//随着代码的增多，有可能在document加一个点击事件
			document.onclick = function  () {
				//隐藏box
				oBox.style.display = "none"
				
			}
			function stopEvent (ev) { 
				var ev = ev || event 
				if (ev && ev.stopPropagation) { 
					ev.stopPropagation() 
				} else if(window.event){ 
					window.event.cancelBubble = true 
				} 
			}
		</script>
	</body>
</html>
